﻿
using System;

namespace SharePoint.Orm.Helpers {
	/// <summary>
	/// Methods for working with <see cref="Guid"/>s.
	/// </summary>
	public static class GuidHelper {
		/// <summary>
		/// Converts a <see cref="Guid"/> into a string suitable for most SharePoint methods.
		/// </summary>
		/// <param name="guid">The <see cref="Guid"/> to convert.</param>
		/// <returns>The guid string.</returns>
		public static string ToSPString(Guid guid) {
			return guid.ToString("B").ToUpper();
		}

		///<summary>
		/// Try to parse a string into a <see cref="Guid"/>.
		///</summary>
		///<param name="str">The string to parse.</param>
		///<param name="guid">The <see cref="Guid"/> that was parsed.</param>
		///<returns>True, if successful. False, if failed to parse.</returns>
		public static bool TryParse(string str, out Guid guid) {
			try {
				guid = new Guid(str);
				return true;
			} catch (Exception) {
				guid = default(Guid);
				return false;
			}
		}
	}
}
